package com.lagou.rpc.consumer.controller;

import com.alibaba.fastjson.JSONObject;
import com.lagou.rpc.api.IUserService;
import com.lagou.rpc.consumer.proxy.RpcClientProxy;
import com.lagou.rpc.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author swzhang
 * @version v1.0
 * @date 2022-01-28 11:34
 */
@RestController
@RequestMapping("demo")
public class DemoController {

    @Autowired
    private RpcClientProxy proxy;

    @RequestMapping(path = "/getUser", method = RequestMethod.GET)
    public String getUser(int id) {
        IUserService userService = (IUserService) proxy.createProxy(IUserService.class);
        User user = userService.getById(id);
        System.out.println(user);

        return JSONObject.toJSONString(user);
    }
}
